<%@ page language="java" import="java.util.*,com.hs.auth.model.*,com.hs.core.cache.*,com.hs.dnms.model.*" pageEncoding="utf-8"%>
 <%
   DnmsBook obj = (DnmsBook)request.getAttribute("obj"); 
   List modlist = (List)request.getAttribute("modlist");
 
  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="../../include.jsp"%>  
<script language="javascript" type="text/javascript" src="<%=basePath%>common/uploadify/jquery-1.4.2.min.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>common/javascripts/My97DatePicker/WdatePicker.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>common/uploadify/jquery.uploadify.v2.1.4.js"></script>
<script type="text/javascript" src="<%=basePath%>common/uploadify/swfobject.js"></script>
<LINK rel=stylesheet type=text/css href="<%=basePath%>common/uploadify/uploadify.css"/>  
<script src='<%=basePath%>dwr/interface/dataProhelper.js'></script>  

<script language="javascript" type="text/javascript">
function dataPro(id){
	window.location.href="";

}
/**
文件上传
*/
$(document).ready(function()
        {   
            $("#uploadify").uploadify({ 
            'uploader': '<%=basePath%>common/uploadify/uploadify.swf',
	　　		'script': '<%=basePath%>produce/fileSave.do?id=<%=obj==null?"":obj.getId()%>', 
	　　		'cancelImg': '<%=basePath%>common/uploadify/cancel.png', 
	        'queueID':'fileQueue', 
	        'fileDataName':'bookfile',
	        'fileExt': '*.PDF;*.pdf;',
	        'fileDesc':'请选择PDF文件类型',  
        	'wmode': 'transparent', 
        	'auto': false,
       		'multi': true,
       		'simUploadLimit':999,
       		'buttonImg':'<%=path%>/common/uploadify/selectfile.gif',
       		'sizeLimit':9999999999,
        	'onSelect':function(){
        	    
        	    // $("#uploadify").uploadifySettings('script',urlinit);
        	},
        	'onProgress':function(){
        		 _grayWindow(true); 
        	},
        	'onComplete': function (event, queueID, fileObj, response, data)
		     { 
		         var returnstr = response; 
 		         callback4Fileinsert(returnstr);
		     } ,
		     'onError': function(event, queueID, fileObj) {  
					alert("文件上传异常:" + event);  
			 }
        	
　　         });
         });
function uploadfile(){ 
	           $('#uploadify').uploadifyUpload();
	       }
/**
文件上传回调函数
*/	       
var fileid = 0;
function callback4Fileinsert(message){   
     var cellFunctions = [   
          function(item) {   
           	return "<a href=javaScript:viewPdfFile('"+item.id+"')>"+item.fileName+"</a>";
          }, 
          function(item) {  
           	return "<input type='button' onclick=downLoadFile('"+item.id+"') value='下载' class='but_2' />&nbsp;";
          }, 
          function(item) {  
           	return "<input type='button' onclick=deleteFile('"+item.id+"'); value='删除' class='but_2'/>";
          }
      ];    
     var index = message.indexOf("$"); 
     fileid = message.substring(0,index); 
     var rowdata = message.substring(index+1); 
     var data = eval('('+rowdata+')');   
      DWRUtil.addRows("listfile", data, cellFunctions,{
          rowCreator:function(options) { //自定义 tr 的创建行为 
          var trobj = document.createElement("tr");   
          trobj.setAttribute("id","file_"+fileid); 
          return trobj; 
     },cellCreator:function(options) {
	var cell = document.createElement("td"); 
	if(options.cellNum==0) {//表示第一列，以此类推   
	  	cell.width = "80%";
		}else{
		    cell.width = "10%";
	    cell.align="center";
	     
	}
	return cell;
}, escapeHtml:false
     });
    alert('文件上传成功！');  
     _grayWindow(false); 
    }
	       function callback4FileDelete(data){  
	       		var tbody  = document.getElementById("listfile");// tbody 的id
        		var rowobj = document.getElementById("file_"+data); 
        		tbody.removeChild(rowobj);
	       }
	       function deleteFile(fileid){ 
	       		if(confirm("确认要删除该文档吗?")){
	       			dataProhelper.deleteFile(fileid,callback4FileDelete);
	       		} 
	       }	   
	       
/**疾病信息保存*/
function saveDisinfo(id){
	
 	var disname = document.getElementById("disname").value;
	if(isNull(disname)){
		alert("请输入古籍中医病名！");
		return;
	}
	//if(!isNull(disid))
    	//dataProhelper.updateDis(disid,disname,disnamen,'0',istangyao,iszhongchengyao,isxiyi,istuina,iszhenjiu,isshoushu,curemethod,callback4addDis);
  //  else
   		dataProhelper.addDis(id,disname,'','0','','','','','','','',callback4addDis);
    //dataProhelper.saveDocInfo('<%=obj.getId()%>',doctype,doccatagory);
}
var disid = 0;
function callback4addDis(data){  
 	var index = data.indexOf("$");
    var disid = data.substring(0,index);
    var disname = data.substring(index+1);  
    var str = "<span id=para_"+disid+"><input type=radio onclick=viewpre('"+disid+"') value="+disid+" name=dis><font size='5'>"+disname+"</font>"+"<a href=javaScript:delDis('"+disid+"');>"+" 删 除 </a></span>";      	             
    var objHtml = document.getElementById("paras");
    var temp = objHtml.innerHTML + str;
    objHtml.innerHTML = temp; 
    alert('古籍疾病信息保存成功！');   
    document.getElementById("disname").value='';
    document.getElementById("disname").focus(); 
    //alert('疾病信息保存成功！');   
    //document.getElementById("disid").value = message;
    //window.parent.dataframe.frameElement.src = "<%=basePath %>produce/datamain.do?id=<%=obj.getId()%>&disid="+message;
}
 
 function callback4DisDelete(data){    
    //var tbody  = document.getElementById("dislist");// tbody 的id 
    //var rowobj = document.getElementById("dis_"+data);  
    //tbody.removeChild(rowobj);
    alert("疾病信息删除成功");
    window.parent.document.location.replace(window.parent.document.location.href);
    
 }  
 function downLoadFile(id){
 	window.location.href="<%=basePath%>produce/downloadFile.do?pid="+id;
 
 
 }
 function uploadfile(id){ 
 	openwindow("<%=basePath%>produce/uploadFile.do?id="+id,'600','400',''); 
 }
function delDis(disid){
	if(confirm("确认要删除该疾病及其相关信息吗？")){
    		dataProhelper.delDis(disid,callback4delcheck);
    }
}
function callback4delcheck(data){
	alert("删除成功");
	document.getElementById("para_"+data).style.display="none"; 
}

function viewpre(id){ 
    DWRUtil.removeAllRows("prelist");
    window.parent.dataframe.frameElement.src = "<%=basePath%>produce/datamain.do?disid="+id;
	dataProhelper.queryModByDisid(id,callback4preview);
}
function callback4preview(data){   
	var dataarr = data.split("#")  
	for(var i = 0;i<dataarr.length;i++){ 
	    var temp = dataarr[i];
	    if("" == temp)
	       continue;
	    addpre(temp);
	}
}
function addpre(message){ 
	   var cellFunctions = [ 
          function(item) {   
           	return item.distype;
          }, 
          function(item) {  
           	return item.modendis;
          }, 
          function(item) {  
           	return "<a href=javaScript:onclick=deletePre('"+item.id+"')>删除</a><input type=hidden value='"+item.id+"' name='preid_"+item.id + "' id='preid_"+item.id+"/>";
          }
      ];    
     var index = message.indexOf("$");  
     disid = message.substring(0,index); 
     var rowdata = message.substring(index+1); 
     var data = eval('('+rowdata+')');   
     	  DWRUtil.addRows("prelist", data, cellFunctions,{
          rowCreator:function(options) { //自定义 tr 的创建行为 
          var trobj = document.createElement("tr");   
          trobj.setAttribute("id","pre_"+disid);  
          return trobj; 
     },cellCreator:function(options) {
		var cell = document.createElement("td"); 
		return cell;
	 }, escapeHtml:false
     });
    
}
var bookid = <%=obj==null?"":obj.getId()%>;
function saveModDisinfo(distype){
	var disid = getRadioValue("dis");
	if("undefined" == typeof(disid)){
		alert("请先选择古籍中医病名！");
		return;
	} 
	var modendis ;
	if(distype == "2"){
		modendis = document.getElementById("modendis").value; 
		if(isNull(modendis)){
			alert("请输入现代西医病名！");
			return; 
	    }
	}else if(distype == "1"){
		modendis = document.getElementById("modcndis").value; 
		if(isNull(modendis)){
			alert("请输入现代中医病名！");
			return; 
	    }
	}
 	
    dataProhelper.addAncMod(modendis,distype,disid,bookid,callback4addPre);
}
function callback4addPre(message){ 
	   var cellFunctions = [ 
          function(item) {   
           	return item.distype;
          }, 
          function(item) {  
           	return item.modendis;
          }, 
          function(item) {  
           	return "<a href=javaScript:onclick=deletePre('"+item.id+"')>删除</a><input type=hidden value='"+item.id+"' name='preid_"+item.id + "' id='preid_"+item.id+"/>";
          }
      ];    
     var index = message.indexOf("$");  
     disid = message.substring(0,index); 
     var rowdata = message.substring(index+1); 
     var data = eval('('+rowdata+')');   
     	  DWRUtil.addRows("prelist", data, cellFunctions,{
          rowCreator:function(options) { //自定义 tr 的创建行为 
          var trobj = document.createElement("tr");   
          trobj.setAttribute("id","pre_"+disid);  
          return trobj; 
     },cellCreator:function(options) {
		var cell = document.createElement("td"); 
		return cell;
	 }, escapeHtml:false
     });
    alert('现代西医疾病保存成功！');   
}

function deletePre(id){  
	if(confirm("确认要删除现代疾病吗？")){
	       dataProhelper.delAncMod(id,callback4delPre); 
    }
}
function callback4delPre(data){   
	var tbody  = document.getElementById("prelist");// tbody 的id 
    var rowobj = document.getElementById("pre_"+data);  
    tbody.removeChild(rowobj);
    alert("现代疾病删除成功！");
}

/**疾病信息保存结束**/	           
</script>
</head>
<body>
<div class="deta_proce">
    <ul>
        <li>数据加工</li> 
    </ul>
    <div>
        <table border="0" cellspacing="0" cellpadding="0"> 
          <caption>
           导入数据
          </caption>
          <tr>
            <td width="15%" nowrap>书籍名称：</td> 
            <td><%=obj==null?"":obj.getBookname() %>
            <input type="hidden" name="bookid" id="bookid" value="<%=obj==null?"":obj.getId() %>" style="width:99%"/></td> 
          </tr> 
           <tr>
            <td width="15%" nowrap>病名：</td> 
            <td><%=obj==null?"":obj.getDiseasename() %>
          </tr> 
           <tr>
            <td width="15%" nowrap>原文文本：</td> 
            <td><%=obj==null?"":obj.getOriginaltext() %>
          </tr> 
        </table>  
        <table border="0" cellspacing="0" cellpadding="0"  class="atta_tab">
          <caption>数据加工</caption> 
          <tr> 
           <td width="40%">古籍中医病名：</td>
           <td width="50%"><input type="text" name="disname" id="disname" style="width:99%"/></td>
           <td width="10%"><input onclick="saveDisinfo('<%=obj==null?"":obj.getId() %>')" type="button" value="保存" class="but_3"/></td>
          </tr>
          <tr>
           <td colspan="3" id="paras">
           <%
            if(null != obj && !(obj.getDisset().isEmpty())){  
                   Iterator disiter = obj.getDisset().iterator(); 
                   while(disiter.hasNext()){ 
          	             DnmsDisease disobj = (DnmsDisease)disiter.next(); 
          	             Long disid = disobj.getId(); 
          	             out.print("<span id=para_"+disid+"><input type=radio onclick=viewpre('"+disid+"') value="+disid+" name=dis><font size='5'>"+disobj.getDiseasename()+"</font>");
          	             out.print("<a href=javaScript:delDis('"+disid+"');>");
          	             out.print(" 删 除 </a></span>"); 
		          	    //symstr.append("<option value='");
		          	   // symstr.append(pid);
		          	   // symstr.append("'>");
		          	  //  symstr.append(para.getSymptomname());
		          	   // symstr.append("</option>");
           }}else{ 
              } %> 
           </td> 
	       </tr> 
        </table>
        <table border="0" cellspacing="0" cellpadding="0" class="atta_tab">
          <caption>疾病信息</caption>  
          <tr> 
            <th width="30%">类型</th>
            <th width="50%">现代病名</th>
            <th width="10%">删除</th>
          </tr>
          <tbody id=prelist> 
           </tbody>
        </table>
         <table border="0" cellspacing="0" cellpadding="0" class="atta_tab"> 
          <tr>
            <td width="20%">现代西医病名</td>
            <td width="60%">
            <select id="modendis" name="modendis" style="width:100%">
            <%
            	if(modlist != null && modlist.size()>0){
					for(int i =0;i<modlist.size();i++){
						Map data = (Map)modlist.get(i);
						if(data.get("distype").equals("2")){
			%>
				<option value='<%=data.get("id") %>'><%=data.get("disname") %></option>
			<%	
						}
					}
				} 
             %>
            </select>
            </td>
            <td width="10%"><input onclick="saveModDisinfo(2)" type="button" value=" 保 存 " class="but_2"/></td>
          </tr>
          <tr>
            <td width="20%">现代中医病名</td>
            <td width="60%">
             <select id="modcndis" name="modcndis" style="width:100%">
            <%
            	if(modlist != null && modlist.size()>0){
					for(int i =0;i<modlist.size();i++){
						Map data = (Map)modlist.get(i);
						if(data.get("distype").equals("1")){
			%>
				<option value='<%=data.get("id") %>'><%=data.get("disname") %></option>
			<%	
						}
					}
				} 
             %>
            </select>
            </td>
            <td width="10%"><input onclick="saveModDisinfo(1)" type="button" value=" 保 存 " class="but_2"/></td>
          </tr>    
        </table> 
        <table border="0" cellspacing="0" cellpadding="0" class="atta_tab">
          <caption>
          已上传附件
          </caption>
          <tr>
             <th>文件名称</th>
            <th width="10%">下载</th>
            <th width="10%">删除</th>
          </tr>
           <tbody id="listfile">
          <%
             if(null != obj.getFileset() && !(obj.getFileset().isEmpty())){
                   Iterator iter = obj.getFileset().iterator();
                   int i = 0;  
                   while(iter.hasNext()){
          	             DnmsFile fileobj = (DnmsFile)iter.next();
          	             i++; 
          	             Long fileid = fileobj.getId();
          	               
           %>
          <tr id="file_<%=fileid %>">
            <td><a href="javaScript:downLoadFile('<%=fileid %>')"><%=fileobj.getFilename() %></a> </td>
            <td><a href="javascript:onclick=downLoadFile('<%=fileid %>');">下载</a> </td>
            <td><a href="javascript:onclick=deleteFile('<%=fileid %>');">删除</a></td>
          </tr>
          <%}}else{ %> 
          </tbody>
          <%} %> 
           
        </table> 
        <div class="tac">
            <input onclick="uploadfile('<%=obj.getId() %>')" type="button" value=" 原文上传 " class="but_3"/> 
        </div> 
        
    </div>
</div> 
</body>
</html>

